package cn.bdqn.asecu.service;

import cn.bdqn.pojo.ChatRoom;
import cn.bdqn.pojo.Message;
import cn.bdqn.pojo.Project;
import cn.bdqn.repository.Asect_ChatRoomRepository;
import cn.bdqn.repository.Asecu_MessageRepository;
import cn.bdqn.repository.Asecu_ProjectRepository;
import cn.bdqn.vo.UserChatRoom;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class ChatRoomService {

    @Resource
    Asect_ChatRoomRepository asect_chatRoomRepository;

    @Resource
    Asecu_MessageRepository asecu_messageRepository;

    @Resource
    Asecu_ProjectRepository asecu_projectRepository;
    public List<UserChatRoom> getPro() {
        List<UserChatRoom> pro = asect_chatRoomRepository.getPro();
        return pro;
    }

    public void fasong(Integer id, Integer[] song, String content) {
        Project project = new Project();
        for (Integer i : song) {
            project = asecu_projectRepository.findById(i).get();
            Message message = new Message();
            message.setContent(content);
            message.setStatime(new Date());
            message.setBeenread(0);
            message.setUserId(id);
            message.setStatus(1);
            message.setType(project.getName());
            message.setHaveId(project.getUserId());
            asecu_messageRepository.save(message);
        }
        ChatRoom chatRoom = new ChatRoom();
        chatRoom.setTheme(content);
        chatRoom.setMsgId(0);
        System.out.println("??");
        asect_chatRoomRepository.save(chatRoom);

    }
}
